const Excel = require('exceljs');
const excelFile = "../../assets/excel/word.xlsx";


var workbook = new Excel.Workbook();

function readExcel (fileName) {
  return new Promise((resolve, reject) => {
    let result = [];
    workbook.xlsx.readFile(fileName).then(function () {
      var worksheet = workbook.getWorksheet(1); //获取第一个worksheet
      worksheet.eachRow(function (row, rowNumber) {
        const obj = {
          "word": row.values[1],
          "pronunciation": row.values[2],
          "explanation": row.values[3]
        }
        result.push(obj);
      });
      resolve(result);
    });
  })
}

async function getExcelDataToArray() {
  const result = await readExcel(excelFile);
  return result;
}
module.exports = getExcelDataToArray;

